package com.lyf.controller.admin;

import com.lyf.result.Result;
import com.lyf.service.admin.WorkSpaceService;
import com.lyf.vo.BusinessDataVO;
import com.lyf.vo.DishOverViewVO;
import com.lyf.vo.OrderOverViewVO;
import com.lyf.vo.SetmealOverViewVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api( tags = "工作台管理")
@RequestMapping("/admin/workspace")
public class WorkSpaceController {
    @Autowired
    private WorkSpaceService workSpaceService;

    @ApiOperation("获取今日营业数据")
    @GetMapping("/businessData")
    public Result getBusinessData() {
        log.info("获取今日营业数据");
        BusinessDataVO businessDataVO = workSpaceService.getBusinessData();
        // 检查营业数据，如果有字段值为null则设置为0
        businessDataVO.setTurnover(businessDataVO.getTurnover() == null ? 0.0 : businessDataVO.getTurnover());
        businessDataVO.setUnitPrice(businessDataVO.getUnitPrice() == null ? 0.0 : businessDataVO.getUnitPrice());
        businessDataVO.setNewUsers(businessDataVO.getNewUsers() == null ? 0 : businessDataVO.getNewUsers());
        return Result.success(businessDataVO);
    }

    @ApiOperation("菜品总览")
    @GetMapping("/overviewDishes")
    public Result overviewDishes() {
        log.info("菜品总览");
        DishOverViewVO dishOverViewVO = workSpaceService.overviewDishes();
        return Result.success(dishOverViewVO);
    }

    @ApiOperation("套餐总览")
    @GetMapping("/overviewSetmeals")
    public Result overviewSetmeals() {
        log.info("套餐总览");
        SetmealOverViewVO setmealOverViewVO = workSpaceService.overviewSetmeals();
        return Result.success(setmealOverViewVO);
    }

    @ApiOperation("订单总览")
    @GetMapping("/overviewOrders")
    public Result overviewOrders() {
        log.info("订单总览");
        OrderOverViewVO orderOverViewVO = workSpaceService.overviewOrders();
        return Result.success(orderOverViewVO);
    }

}
